﻿using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace FutureCorePlugin
{
    public class CircleJoystick : ScrollRect
    {
        protected float mRadius = 0f;

        protected override void Start()
        {
            base.Start();
            // 摇杆半径
            mRadius = (transform as RectTransform).sizeDelta.x * 0.5f;
        }

        public override void OnDrag(PointerEventData eventData)
        {
            base.OnDrag(eventData);
            Vector2 contentPostion = content.anchoredPosition;
            if (contentPostion.magnitude > mRadius)
            {
                contentPostion = contentPostion.normalized * mRadius;
                SetContentAnchoredPosition(contentPostion);
            }
        }
    }
}